package com.czy.owner.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.entity.OrdersListModel;
import com.czy.owner.entity.UptoTodayModel;
import com.czy.owner.utils.glide.GlideUtils;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;


/**
 * Created by wangyang on 2017/4/20 0020.
 */
public class UptoTodayAdapter extends RecyclerArrayAdapter<UptoTodayModel.GoodsListBean> {

    private Context context;

    public UptoTodayAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new UptoTodayAdapter.OrderSubViewHolder(parent);

    }

    class OrderSubViewHolder extends BaseViewHolder<UptoTodayModel.GoodsListBean> {
        private ImageView imgProduct;
        private TextView tvProductDescription;
        private TextView tvProductPrice;
        private TextView tvProductCount;

        public OrderSubViewHolder(ViewGroup parent) {
            super(parent, R.layout.item_order_sub);
            imgProduct = $(R.id.img_product);
            tvProductDescription = $(R.id.tv_product_description);
            tvProductPrice = $(R.id.tv_product_price);
            tvProductCount = $(R.id.tv_product_count);

        }

        @Override
        public void setData(UptoTodayModel.GoodsListBean data) {
            tvProductDescription.setText(data.getGoodsName());
            tvProductPrice.setText("￥" + String.format("%.2f", data.getPrice()));
            tvProductCount.setVisibility(View.GONE);
            GlideUtils.loadImage(context, data.getGoodsLogo(), imgProduct, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                @Override
                public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                }

                @Override
                public void onLoadingError(String source, Exception e) {

                }
            }, R.mipmap.default_icon, R.mipmap.default_icon);

        }

    }
}
